//
//  HFViewController.m
//  HFCalendar
//
//  Created by liuhongfei on 08/24/2021.
//  Copyright (c) 2021 liuhongfei. All rights reserved.
//

#import "HFViewController.h"
#import <HFCalendarHeader.h>
#import <HFDateSelectViewController.h>

@interface HFViewController ()

@property (nonatomic, copy) NSString *startDateStr;
@property (nonatomic, copy) NSString *endDateStr;

@end

@implementation HFViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(50, 150, SCREEN_WIDTH - 100, 60);
    [button setTitle:@"打开日历" forState:UIControlStateNormal];
    [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15.f];
    button.backgroundColor = HFHexColor(0x1678FF);
    [button addTarget:self action:@selector(buttonDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

- (void)buttonDidClick {
    HFDateSelectViewController *dateVC = [[HFDateSelectViewController alloc] init];
    
    __weak typeof(self)weakSelf = self;
    
    dateVC.date_callBack = ^(NSString * _Nonnull dateStr) {
        NSArray *arr = [dateStr componentsSeparatedByString:@"-"];
        if (arr.count > 1) {
            weakSelf.startDateStr = arr[0];
            weakSelf.endDateStr = arr[1];
        } else {
            weakSelf.startDateStr = arr[0];
        }
    };
    
    NSMutableArray *mutArray = [@[] mutableCopy];
    if (self.startDateStr.length > 0) {
        [mutArray addObject:self.startDateStr];
    }
    if (self.endDateStr.length > 0) {
        [mutArray addObject:self.endDateStr];
    }
    dateVC.dateArray = mutArray;
    
    [dateVC showCalendarWithVC:self];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
